﻿using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace HelenServer.Data.SqlServer;

public class CompositStringToInt32ValueConverter : ValueConverter<int[], string>
{
    public CompositStringToInt32ValueConverter()
        : base(
            model => string.Join('#', model),
            provider => Array.ConvertAll(provider.Split('#', StringSplitOptions.RemoveEmptyEntries), s => StringToInt32(s)))
    {

    }

    private static int StringToInt32(string value)
    {
        return int.TryParse(value, out var num) ? num : -1;
    }
}